<?php
class Server {
  public static function submit_obj($orm, $sys, $inst, $is_iframe) {
    $req = json_decode(Utils::get_param('req', '[]'));
    $orm->update('pb_ht_hm_data', $req);
  }
  
  public static function delete_file($orm, $sys, $inst, $is_iframe) {
    $req = json_decode(Utils::get_param('req', '[]'));
    
    if (file_exists($req->link)) {
      unlink($req->link);
    }
    
    $orm->delete('pb_ht_hm_image', $req);
  }
  
  
  public static function upload_icon($orm, $sys, $inst, $is_iframe) {
    if (isset($_FILES['Filedata']) && is_uploaded_file($_FILES['Filedata']['tmp_name']) && $_FILES['Filedata']['error'] == 0) {
      //获得上传文件信息
      $upload_file = $_FILES['Filedata'];
      //获取文件扩展名
      $file_info = pathinfo($upload_file['name']);
      $file_ext = (isset($file_info['extension'])) ? $file_info['extension'] : '';
      
      $updir = UPLOAD_DIR_PLGN . $inst->__folder;
      if (!file_exists($updir)) {
        Utils::create($updir);
      }
        
      //获取客户端参数
      
      //Add custom code here...
      $file_ext = strtolower((isset($file_info['extension'])) ? $file_info['extension'] : '');
      $res = new stdClass();
      $res->name = $file_info['filename'] . '.' . $file_ext;
      $res->link = $updir . '/' . Utils::unique() . '.' . $file_ext;
      if (move_uploaded_file($upload_file['tmp_name'], $res->link)) {
        $orm->add('pb_ht_hm_image', $res);
        $res->id = $orm->last_id();
        echo json_encode($res);
      }
    }
  }
}
?>